import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';

import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { InMemoryDataService } from './in-memory-data.service';

import { SpyDirective } from './spy.directive';
import { DynamicHostDirective } from './dynamic-host.directive';

import { AppComponent } from './app.component';
import { TestComponent } from './test/test.component';
import { TestDetailComponent } from './test-detail/test-detail.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { TestGetDetailComponent } from './test-get-detail/test-get-detail.component';
import { DynamicFormComponent } from './dynamic-form/dynamic-form.component';
import { DynamicUserComponent } from './dynamic-user/dynamic-user.component';
import { DynamicRenderComponent } from './dynamic-render/dynamic-render.component';
import { DynamicChildAComponent } from './dynamic-render/dynamic-render-childa.component';
import { DynamicChildBComponent } from './dynamic-render/dynamic-render-childb.component';
import { TestInterceptor1, TestInterceptor2 } from './share/testinterceptor';
import { GlobalConfig } from './share/global.config';

@NgModule({
  declarations: [
    AppComponent,
    TestComponent,
    TestDetailComponent,
    DashboardComponent,
    TestGetDetailComponent,
    DynamicFormComponent,
    DynamicUserComponent,
    DynamicRenderComponent,
    DynamicChildAComponent,
    DynamicChildBComponent,
    SpyDirective,
    DynamicHostDirective
  ],
  imports: [
    BrowserModule,
    // 模板驱动表单支持
    FormsModule,
    // 响应式表单支持
    ReactiveFormsModule,
    // http支持
    HttpClientModule,
    // http内存模拟数据
    HttpClientInMemoryWebApiModule.forRoot(
      InMemoryDataService, { dataEncapsulation: false }
    ),
    // 自定义模块

    // 路由模块
    AppRoutingModule
  ],
  // 动态加载的组件
  entryComponents: [
    DynamicChildAComponent,
    DynamicChildBComponent,
  ],
  // 服务
  providers: [
    { provide: GlobalConfig, useValue: {httpRetryTimes: 0} },
    { provide: HTTP_INTERCEPTORS, useClass: TestInterceptor1, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: TestInterceptor2, multi: true }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
